package com.cdxy.biz.process.impl;

import com.cdxy.biz.process.IAxUserBizProcess;
import com.cdxy.dmr.dataObject.AxUserDO;
import com.cdxy.dmr.repository.AxUserRepository;
import com.cdxy.enums.BizErrorEnum;
import com.cdxy.enums.KaptchaEnum;
import com.cdxy.model.dto.base.exception.BusinessException;
import com.cdxy.model.dto.req.ModifyBindPhoneReq;
import com.cdxy.model.dto.req.ModifyUserInfoReq;
import com.cdxy.model.dto.req.SendMobileCodeReq;
import com.cdxy.service.IAxUserService;
import com.cdxy.service.ISmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: tangy
 * @Date: 2020/3/22 14:05
 */
@Service
public class AxUserBizProcessImpl implements IAxUserBizProcess {

    @Autowired
    private IAxUserService axUserService;

    @Autowired
    private AxUserRepository axUserRepository;

    @Autowired
    private ISmsService smsService;

    @Override
    public void modifyUserInfo(ModifyUserInfoReq modifyUserInfoReq) {
        axUserService.modifyUserInfo(modifyUserInfoReq);
    }

    @Override
    public void modifyBindPhoneSendSms(SendMobileCodeReq sendMobileCodeReq) {
        String phone = sendMobileCodeReq.getPhone();
        AxUserDO axUserDO = axUserRepository.getByMobile(phone);
        if (axUserDO != null) {
            throw new BusinessException(BizErrorEnum.PHONE_HAD_BIND);
        }

        smsService.sendSms(KaptchaEnum.BusinessCode.MODIFY_BIND_PHONE, phone);
    }

    @Override
    public void modifyBindPhone(ModifyBindPhoneReq modifyBindPhoneReq) {
        axUserService.modifyBindPhone(modifyBindPhoneReq);
    }
}
